package com.guoshengdeu.door.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.guoshengdeu.door.entity.Thumbnail;
import com.guoshengdeu.door.service.IThumbnailService;
import com.guoshengdeu.door.util.RespResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yfly
 * @since 2021-06-01
 */
@Api("缩略图")
@RestController
@RequestMapping("/thumbnail")
public class ThumbnailController {

    @Autowired
    private IThumbnailService thumbnailService;

    //查询缩略图
    @ApiOperation("添查询")
    @RequestMapping("list")
    public List<Thumbnail> queryThumbnail(){
        return thumbnailService.list();
    }

    //添加更新
    @ApiOperation("添加更新")
    @RequestMapping("addthumbnail")
    public RespResult addthumbnail(@RequestBody Thumbnail thumbnail){
        boolean saveOrUpdate = thumbnailService.saveOrUpdate(thumbnail);
        if (saveOrUpdate){
            return RespResult.success();
        }
        return RespResult.error("添加或更新失败");
    }

    //删除thumbnail
    @ApiOperation("删除")
    @DeleteMapping("delethumbnail")
    public RespResult delethumbnail(@PathVariable Integer id){
        boolean removeById = thumbnailService.removeById(id);
        if (removeById){
            return RespResult.success();
        }
        return RespResult.error("删除失败");
    }

    //分页
    @ApiOperation("分页")
    @GetMapping("page")
    public RespResult Page(Page<Thumbnail> page){
        Page<Thumbnail> pages = thumbnailService.page(page);
        return RespResult.success();
    }
}
